home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-12-02 | 3.2 KB | 182 lines | [TEXT/CWIE] |
- /*
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
- */
-
- #include "ScriptableStuffItEngine.h" // app
- #include "FullPath.h" // MoreFiles
-
- #ifndef __LOWMEM__
- # include <LowMem.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- # include <AppleEvents.h>
- #endif
-
- #ifndef __SOUND__
- # include <Sound.h>
- #endif
-
- Boolean gQuitting;
-
- static pascal OSErr SetUpMenuBar (void)
- {
- OSErr err = noErr;
-
- Handle menuBar = GetNewMBar (128);
-
- if (!menuBar)
- err = nilHandleErr;
- else
- {
- SetMenuBar (menuBar);
- DisposeHandle (menuBar);
- InvalMenuBar ( );
- }
-
- return err;
- }
-
- static pascal OSErr ProcessFileMenuCommand (short command)
- {
- OSErr err = noErr;
-
- if (command == 1)
- gQuitting = true;
-
- return err;
- }
-
- static pascal OSErr ProcessMenuCommand (long command)
- {
- OSErr err = noErr;
-
- switch (command >> 16)
- {
- case 128 : // apple menu
- break;
- case 129 : // file menu
- err = ProcessFileMenuCommand (command);
- break;
- }
-
- return err;
- }
-
- static pascal OSErr ProcessKeyDown (const EventRecord &event)
- {
- OSErr err = noErr;
-
- if (event.modifiers & cmdKey)
- err = ProcessMenuCommand (MenuKey (event.message & charCodeMask));
-
- return err;
- }
-
- static pascal OSErr ProcessMouseDown (const EventRecord &event)
- {
- OSErr err = noErr;
-
- WindowRef whichWindow;
-
- short findWindowPartCode = FindWindow (event.where, &whichWindow);
-
- switch (findWindowPartCode)
- {
- case inMenuBar :
-
- err = ProcessMenuCommand (MenuSelect (event.where));
- HiliteMenu (0);
- break;
- }
-
- return err;
- }
-
- static pascal OSErr InitMac (void)
- {
- OSErr err = noErr;
-
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return err;
- }
-
- static pascal OSErr FullPathToFSSpec
- (DescType givenType, const void *data, Size size, DescType desiredType, long, AEDesc *result)
- {
- OSErr err = noErr;
-
- if (givenType == typeChar && desiredType == typeFSS)
- {
- FSSpec fss;
-
- if (!(err = FSpLocationFromFullPath (size,data,&fss)))
- {
- err = AECreateDesc (typeFSS, &fss, sizeof (fss), result);
- }
- }
-
- return err;
- }
-
- void main (void)
- {
- OSErr err = noErr;
-
- if (!(err = InitMac ( )))
- if (!(err = SetUpMenuBar ( )))
- if (!(err = AEInstallEventHandler (typeWildCard,typeWildCard,ScriptableStuffItAppleEventHandler,0,false)))
- if (!(err = AEInstallCoercionHandler (typeChar, typeFSS, AECoercionHandlerUPP (FullPathToFSSpec), 0, false, false)))
- {
- while (!gQuitting)
- {
- EventRecord event;
-
- WaitNextEvent (everyEvent,&event,-1,nil);
-
- switch (event.what)
- {
- case keyDown :
-
- err = ProcessKeyDown (event);
- break;
-
- case kHighLevelEvent :
-
- err = AEProcessAppleEvent (&event);
- break;
-
- case mouseDown :
-
- err = ProcessMouseDown (event);
- break;
- }
-
- if (err)
- {
- SysBeep (-1);
- err = noErr;
- }
- }
- }
-
- if (err)
- {
- SysBeep (-1);
- err = noErr;
- }
- }
-